package com.llcbenwu.social;


import lombok.Data;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

/**
 * @author lilinchun
 * @date 2021/11/2 0002 19:07
 */
@Data
public class LlcSpringSocialConfig extends SpringSocialConfigurer {



    private String filterProcessesUrl;


    //注入成功处理器处理器 -- 为null时走spring-security默认的，否则走传递过来的，这里也就是指可以发送token的
    private SocialAuthenticationFilterPostProcessor socialAuthenticationFilterPostProcessor;


    public LlcSpringSocialConfig(String filterProcessesUrl){
        this.filterProcessesUrl=filterProcessesUrl;
    }

//    unchecked 执行了未检查的转换时的警告
    @SuppressWarnings("unchecked")
    @Override
    protected <T> T postProcess(T object) {
        //在父类处理完SocialAuthenticationFilter之后的基础上，将其默认拦截url改成我们配置的值
        SocialAuthenticationFilter socialAuthenticationFilter= (SocialAuthenticationFilter) super.postProcess(object);
        socialAuthenticationFilter.setFilterProcessesUrl(filterProcessesUrl);
        //如果配置了后置成功处理器，就将其传入
        if(socialAuthenticationFilterPostProcessor !=null ){
            socialAuthenticationFilterPostProcessor.process(socialAuthenticationFilter);
        }
        return (T) socialAuthenticationFilter;
    }

}
